#ifndef __SHMTX_H__
#define __SHMTX_H__

#include "linux_def.h"
#include "core.h"

typedef struct{
	int fd;
	char	*name;
}shmtx_t;

int shmtx_create(shmtx_t *mtx, void *addr, char *name);


static inline int shmtx_trylock(shmtx_t *mtx)
{
    trylock_fd(mtx->fd);

    if (errno == 0) {
        return 1;
    }

    if (errno == EAGAIN) {
        return 0;
    }

    return 0;
}


static inline void shmtx_lock(shmtx_t *mtx)
{
    lock_fd(mtx->fd);

    if (errno == 0) {
        return;
    }
}


static inline void shmtx_unlock(shmtx_t *mtx)
{
    unlock_fd(mtx->fd);

    if (errno == 0) {
        return;
    }
}


void shmtx_destory(shmtx_t *mtx);


#endif
